/*
 * Text.cpp
 *
 *  Created on: 11/11/2011
 *      Author: joagf
 */

/*
 * Text.cpp
 *
 *  Created on: 16/03/2011
 *      Author: joaogf
 */

#include "text.h"

Text::Text(const string &tex,const string &fontName,const SDL_Color &cor) {
        if( TTF_Init() == -1 )
        {
                exit(1);
        }
        font_ = TTF_OpenFont( fontName.c_str(), 28 );
        if (!font_)
        {
                exit(1);
        }
        textColor_ = cor;
        msg_ = TTF_RenderText_Solid( font_, tex.c_str(),textColor_ );
        msgText_ = tex;
}

Text::Text(const string &tex,const string &fontName, const Uint8 &r, const Uint8 &g,const Uint8 &b,const int &size) {
        if( TTF_Init() == -1 )
        {
                exit(1);
        }
        font_ = TTF_OpenFont( fontName.c_str(), size);
        if (!font_)
        {
                exit(1);
        }
        textColor_.r = r;
        textColor_.g = g;
        textColor_.b = b;
        msg_ = TTF_RenderText_Solid( font_, tex.c_str(), textColor_ );
        msgText_ = tex;
}

Text::~Text() {
         TTF_CloseFont( font_ );
         if(msg_)
         {
                 delete msg_;
         }
         TTF_Quit();
}

SDL_Surface *Text::getTextScreen()const
{
        return msg_;
}

const int &Text::width()const
{
        return msg_->w;
}

const int &Text::height()const
{
        return msg_->h;
}

void Text::changeColor(const Uint8 &r,const Uint8 &g, const Uint8 &b)
{
        textColor_.r = r;
        textColor_.g = g;
        textColor_.b = b;
        delete msg_;
        msg_ = TTF_RenderText_Solid( font_, msgText_.c_str(),textColor_ );
}
void Text::changeColor(const ColorsRGB &cor)
{
		textColor_.r = cor.r_;
	    textColor_.g = cor.g_;
	    textColor_.b = cor.b_;
        delete msg_;
        msg_ = TTF_RenderText_Solid( font_, msgText_.c_str(),textColor_ );
}

void Text::setPos(const Point2d &pos)
{
	pos_ = pos;
}

const Point2d& Text::getPos()const
{
	return pos_;
}

